package com.tensquare.test;

import com.alibaba.fastjson.JSON;
import com.aliyuncs.exceptions.ClientException;
import com.tensquare.util.SmsUtil;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * @author zzb
 * @create 2021/2/22
 */@RabbitListener(queues = "sms")
@Component
public class ValidCodeListener {
     @Autowired
     private SmsUtil smsUtil;
     @RabbitHandler
    public void getMessage(Map map){
         System.out.println("map = " + map);
        //接收消息
         String mobile = (String) map.get("mobile");
         String  code = map.get("code")+"";
         String templateCode = "SMS_206550497";
         String signName = "泽易购";
         Map param = new HashMap();
         param.put("code",code);
         //向阿里大于发送消息
         try {
             smsUtil.sendSms(mobile,templateCode,signName, JSON.toJSONString(param));
         } catch (ClientException e) {
             e.printStackTrace();
         }

     }
}
